<html>
<head><meta charset="utf-8"><title>Origin of &quot;evaluation of constant value failed&quot; · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html">Origin of &quot;evaluation of constant value failed&quot;</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238102609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238102609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mike Welsh <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238102609">(May 10 2021 at 08:14)</a>:</h4>
<p>My project is hitting <code>evaluation of constant value failed</code> from this faux static assert in core::arch on nightly: <a href="https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/macros.rs#L5-L10">https://github.com/rust-lang/stdarch/blob/master/crates/core_arch/src/macros.rs#L5-L10</a> I assume it's originating from one of my dependencies that are using SIMD but I don't know how to tell which one, or how to get more info -- the error only points to that line inside rustlib. --verbose or RUST_BACKTRACE=1 doesn't seem to help. Any advice on how to track this down?</p>



<a name="238104784"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238104784" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pointerbender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238104784">(May 10 2021 at 08:30)</a>:</h4>
<p><span class="user-mention" data-user-id="373265">@Mike Welsh</span> I believe I have seen this particular error before whenever there is a division by zero in one of the <code>const</code>. There are two places in the code you linked where you could investigate this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="p">((</span><span class="n">IMM</span><span class="w"> </span><span class="o">&gt;=</span><span class="w"> </span><span class="n">MIN</span><span class="w"> </span><span class="o">&amp;&amp;</span><span class="w"> </span><span class="n">IMM</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="n">MAX</span><span class="p">)</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">);</span><span class="w"> </span><span class="c1">// line 8</span>
<span class="kd">let</span><span class="w"> </span><span class="n">_</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="o">/</span><span class="w"> </span><span class="p">(</span><span class="cp">$e</span><span class="w"> </span><span class="k">as</span><span class="w"> </span><span class="kt">usize</span><span class="p">);</span><span class="w"> </span><span class="c1">// line 74</span>
</code></pre></div>
<p>Btw, that's a pretty cool way of doing static assertions, I hadn't seen this approach yet, neat!</p>



<a name="238105117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238105117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mike Welsh <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238105117">(May 10 2021 at 08:33)</a>:</h4>
<p>The issue is an unknown dependency of my crate is calling those functions in core::arch (probably by using simd intrinsics with invalid arguments), and I don't know how to tell which one to fix or report the issue.</p>



<a name="238105446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238105446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pointerbender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238105446">(May 10 2021 at 08:36)</a>:</h4>
<p>Hmm, yeah that's a though one.</p>



<a name="238105584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238105584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Pointerbender <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238105584">(May 10 2021 at 08:37)</a>:</h4>
<p>I don't know if it exists, but if there was something like a <code>static_debug_assert!($e != 0)</code> macro, this could maybe yield a better stack trace.</p>



<a name="238106031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238106031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> tm <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238106031">(May 10 2021 at 08:41)</a>:</h4>
<p>The <code>env RUSTC_LOG=info</code> or more specifically <code>env RUSTC_LOG=rustc_mir::interpret=info</code> could shed more light on the source of erroneous constant.</p>



<a name="238106307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238106307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Mike Welsh <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238106307">(May 10 2021 at 08:44)</a>:</h4>
<p>Thanks! I actually just tracked it down to <code>rustfft</code> by grepping .cargo for <code>::arch</code> and a lot of trial and error -- but I'll give this a shot now to see if it's helpful for the future</p>



<a name="238124975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238124975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238124975">(May 10 2021 at 11:34)</a>:</h4>
<p>I was about to link to e.g. the <code>_mm_permute_pd(self, 0x05)</code> for an <code>imm2</code> from <a href="https://github.com/rust-lang/stdarch/blob/c2f21d24b938483d74e277d17fed81a6e7296a97/crates/core_arch/src/x86/avx.rs#L1131-L1132">https://github.com/rust-lang/stdarch/blob/c2f21d24b938483d74e277d17fed81a6e7296a97/crates/core_arch/src/x86/avx.rs#L1131-L1132</a> but it appears someone has already seen these and fixed them in <a href="https://github.com/ejmahler/RustFFT/pull/75">https://github.com/ejmahler/RustFFT/pull/75</a></p>



<a name="238126814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238126814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238126814">(May 10 2021 at 11:49)</a>:</h4>
<p>Unfortunately no one hit this in the crater run for <a href="https://github.com/rust-lang/rust/issues/83278">#83278</a>, and additionally here it appears to require codegen (while the crater run was a check run).</p>



<a name="238127721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238127721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238127721">(May 10 2021 at 11:57)</a>:</h4>
<p>if someone else hits this, here's an example of how it would look. Here on the current <code>RustFFT</code> crate revision on master: we look at the logs around errors, for the frames evaluating the <code>stdarch</code> macros: </p>
<div class="codehilite"><pre><span></span><code>env RUSTC_LOG=rustc_mir::interpret::eval_context=info cargo test 2&gt;&amp;1 | grep &quot;evaluation of constant value failed&quot; -B 10
</code></pre></div>
<p>(this <code>rustfft</code> revision shows this error during tests)</p>



<a name="238127898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238127898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238127898">(May 10 2021 at 11:58)</a>:</h4>
<p>I'm playing around with the grep context so that I can see the logs for the <code>stdarch</code> constants triggering the errors: the ones mentioning <code>core::core_arch::macros::ValidateConstImm</code> (for some it was close, for others less so)</p>



<a name="238127934"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238127934" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238127934">(May 10 2021 at 11:58)</a>:</h4>
<p>(likely the last of those will be the one triggering the error)</p>



<a name="238127998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238127998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238127998">(May 10 2021 at 11:59)</a>:</h4>
<p>and can look like this:</p>
<div class="codehilite"><pre><span></span><code>rustc_mir::interpret::eval_context::frame core::core_arch::macros::ValidateConstImm::&lt;5_i32, 0_i32, 3_i32&gt;::VALID
error[E0080]: evaluation of constant value failed
</code></pre></div>



<a name="238128195"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238128195" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238128195">(May 10 2021 at 12:00)</a>:</h4>
<p>the <code>ValidateConstImm::VALID</code> mechanism is defined <a href="https://github.com/rust-lang/stdarch/blob/655bfc8ac58d659aed47351c591bd4e3d76999e7/crates/core_arch/src/macros.rs#L5-L10">here</a>, and can be read like <code>0 &lt; 5 &lt; 3</code>. The first value comes from the intrinsics const parameters while the other two are the bounds of the immediate's width. The const generic parameter value doesn't fit its expected bounds and the validation constant fails to evaluate.</p>



<a name="238128414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238128414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238128414">(May 10 2021 at 12:02)</a>:</h4>
<p>depending on the intrinsic the source of this failure can be higher up in the logs (some intrinsics call other intrinsics, some intrinsics have multiple const generic parameters, etc; all of which will change these logs, in addition to the user code that calls the intrinsics)</p>



<a name="238128499"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238128499" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238128499">(May 10 2021 at 12:03)</a>:</h4>
<p>some can look like:</p>
<div class="codehilite"><pre><span></span><code>rustc_mir::interpret::eval_context::frame std::arch::x86_64::_mm_permute_pd::&lt;5_i32&gt;
rustc_mir::interpret::eval_context::frame core::core_arch::macros::ValidateConstImm::&lt;5_i32, 0_i32, 3_i32&gt;::VALID
</code></pre></div>
<p>which is where I saw the <code>_mm_permute_pd</code> intrinsic that I mentioned above</p>



<a name="238128676"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238128676" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238128676">(May 10 2021 at 12:04)</a>:</h4>
<p>others will be a bit more hidden, but there was at least this other failure:<br>
<code>rustc_mir::interpret::eval_context::frame core::core_arch::macros::ValidateConstImm::&lt;51_i32, 0_i32, 15_i32&gt;::VALID</code></p>



<a name="238128857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Origin%20of%20%22evaluation%20of%20constant%20value%20failed%22/near/238128857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Origin.20of.20.22evaluation.20of.20constant.20value.20failed.22.html#238128857">(May 10 2021 at 12:06)</a>:</h4>
<p>hope it helps ^^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>